
<?php
	/**
	* @package ParkFind
	* @desc This is the find php script. This script is used for the displaying the search parameters.
	*		The details are pulled from the database and loaded into the drop down boxes.
	*/
	/**
	* @desc This include file will load the directory settings for the Smarty Templates
	*/
	session_start();
	
	//Smarty
	require 'includes/smarty.inc';
	$smarty->assign('title', "Find");
	$smarty->assign('user_id', $_SESSION["user_id"]);	
	$smarty->assign('last', $_SESSION["lastviewed"]);
	$smarty->assign('firstname', $_SESSION["firstname"]);
	$smarty->assign('role', $_SESSION["role"]);
	$smarty->assign('top5', $_SESSION["top5"]);	
	$smarty->display('header.tpl');
	
	/**
	* @desc This include file will load the functions that are required to call 
	*		from the database
	*/
	require 'includes/db_functions.inc';
	/**
	* @desc This include file connects to the database.
	*/
	require 'includes/connect.inc';
	

   	// Name	*************************************
	if (isset($_SESSION["form"]["name"]))
		$smarty->assign('name', $_SESSION["form"]["name"]);

	if (isset($_SESSION["errors"]["name"]))
		$smarty->assign('nameerr', $_SESSION["errors"]["name"]);		


	// Types *************************************
	$types = getParkTypes(); // Get the park types
	$arTypes = array();
	
	if ($types == FALSE)
		$arTypes[] = 'Failed to load';
	else						
		//Iterate through results, extracting park types		
		while($row = mysql_fetch_array($types))
			$arTypes[] = $row["type"];
	
	$smarty->assign('types', $arTypes);
	
	
			
	// Suburbs **********************************
	$suburbs = getSuburbs(); // Get suburbs info
	$arSuburbs = array();
	
	if ($suburbs == FALSE)
		$arSuburbs = array('postcode' => 'error', 'name' => 'Failed to Load');
	else						
		//Iterate through results, extracting suburb name and postcode		
		while($row = mysql_fetch_array($suburbs))
			$arSuburbs[] = array('name' => $row["name"], 'postcode' => $row["postcode"]);
		
	$smarty->assign('suburbs', $arSuburbs);	
		

   	// Regions *************************************	
	$regions = getRegions(); // Get region info
	$arRegions = array();
	
	if ($regions == FALSE)
		$arRegions[] = 'Failed to Load';
	else						
		//Iterate through results, extracting suburb name and postcode		
		while($row = mysql_fetch_array($regions))
			$arRegions[] = $row["name"];
   	
   	$smarty->assign('regions', $arRegions);
	
	$smarty->display('find.tpl');
	
	$smarty->display('footer.tpl');

